﻿#include "stdafx.h"
#include "main_data_c.h"
#include "dsoundHelp.h"

void initDirectSound(HWND hwnd)
{
	HRESULT hr;
	LPDIRECTSOUNDBUFFER pdsBuf = NULL;

	if (!mainData.byte_4919F5) {
		hr = CoInitialize(0);
		hr = DirectSoundCreate8(NULL, &mainData.pdsound_4919FC, NULL);
		if (SUCCEEDED(hr)) {
			hr = mainData.pdsound_4919FC->SetCooperativeLevel(hwnd, DSSCL_PRIORITY);
			if (SUCCEEDED(hr)) {
                mainData.dsoundIsInit_4919F4 = 1;
				//DSBUFFERDESC bufDesc = { 0 };
				//bufDesc.dwSize = sizeof(bufDesc);
				//bufDesc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRL3D;
				//hr = pdsound_4919FC->CreateSoundBuffer(&bufDesc, &pdsBuf, NULL);
				//if (SUCCEEDED(hr)) {
				//	hr = pdsBuf->QueryInterface(IID_IDirectSound3DListener, (LPVOID*)&pdsListener_48D9DC);
				//	if (SUCCEEDED(hr)) {
				//		WAVEFORMATEX wavFormat = { 0 };
				//		wavFormat.wFormatTag = WAVE_FORMAT_PCM;
				//		wavFormat.nChannels = 2;
				//		wavFormat.nSamplesPerSec = 22050;
				//		wavFormat.wBitsPerSample = 16;
				//		wavFormat.nAvgBytesPerSec = wavFormat.nSamplesPerSec * (wavFormat.wBitsPerSample / 8) * wavFormat.nChannels;
				//		wavFormat.nBlockAlign = (wavFormat.wBitsPerSample / 8) * wavFormat.nChannels;
				//		wavFormat.cbSize = sizeof(wavFormat);
				//		hr = pdsBuf->SetFormat(&wavFormat);
				//	}
				//	if (pdsBuf) pdsBuf->Release();
				//}
			}
		}
	}
}
